package com.ytktt.study.week8.task2.service.impl;

import com.ytktt.study.week8.task2.entity.OrderInfoEntity;
import com.ytktt.study.week8.task2.mapper.OrderInfoMapper;
import com.ytktt.study.week8.task2.service.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单业务逻辑实现
 *
 * @author ytk
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class OrderServiceImpl implements OrderService {

    private final OrderInfoMapper orderInfoMapper;

    @Override
    public boolean save(OrderInfoEntity entity) {
        return this.orderInfoMapper.insertSelective(entity) == 1;
    }

    @Override
    public boolean batchSave(List<OrderInfoEntity> list) {
        return this.orderInfoMapper.insertBatch(list) == list.size();
    }

    @Override
    public boolean updateById(OrderInfoEntity entity) {
        return this.orderInfoMapper.updateByPrimaryKeySelective(entity) == 1;
    }

    @Override
    public boolean removeById(Long id) {
        return this.orderInfoMapper.deleteByPrimaryKey(id) == 1;
    }

    @Override
    public boolean removeAll() {
        this.orderInfoMapper.deleteAll();
        return true;
    }

    @Override
    public List<OrderInfoEntity> list() {
        return this.orderInfoMapper.selectAll();
    }

    @Override
    public List<OrderInfoEntity> listByUserId(Integer userId) {
        return this.orderInfoMapper.selectByUserId(userId);
    }
}
